package com.jinke.uang.ui.activity.mine;

import android.annotation.SuppressLint;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jinke.uang.base.BaseNetActivity;
import com.zhengsr.viewpagerlib.indicator.TabIndicator;
import com.jinke.uang.R;
import com.jinke.uang.common.RouterMap;
import com.jinke.uang.ui.fragment.BorrowFinishFragment;
import com.jinke.uang.ui.fragment.BorrowInFragment;

import java.util.ArrayList;
import java.util.List;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 个人中心借款记录的界面
 */
@SuppressLint("SetTextI18n")
@Route(name = "借款记录", path = RouterMap.MINE_BROWING)
public class BorrowingRecordActivity extends BaseNetActivity {

    @BindView(R.id.line_indicator)
    TabIndicator tritabIndecator;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
        List<String> mTitle = new ArrayList<>();
        mTitle.add(getStringResource(R.string.borrow_status_in));
        mTitle.add(getStringResource(R.string.borrow_status_finish));
        BorrowInFragment borrowInFragment = new BorrowInFragment();
        BorrowFinishFragment borrowFinishFragment = new BorrowFinishFragment();
        mFragments.add(borrowInFragment);
        mFragments.add(borrowFinishFragment);
        viewPager.setAdapter(new CusAdapter(getSupportFragmentManager()));
        tritabIndecator.setViewPagerSwitchSpeed(viewPager, 600);
        tritabIndecator.setTabData(viewPager, mTitle, new TabIndicator.TabClickListener() {
            @Override
            public void onClick(int position) {
                viewPager.setCurrentItem(position);
            }
        });
        viewPager.setOffscreenPageLimit(2);
        viewPager.setCurrentItem(0);
    }

    private List<Fragment> mFragments = new ArrayList<>();

    class CusAdapter extends FragmentPagerAdapter {

        public CusAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }
    }

    @Override
    protected void onUIReady() {

    }

    @Override
    protected int getContentResId() {
        return R.layout.activity_borrowing_record;
    }

    @Override
    public String getPageTitle() {
        return getStringResource(R.string.borrow_record_page_title);
    }
}
